package com.kfm.kfmspringboot.model.response;

import lombok.Data;

/**
 * 响应信息实体对象
 * @param <T> 要封装进来的响应信息
 */
@Data
public class ResultVO<T> {

    private static final String ERROR_MSG = "失败！";
    private static final String SUCCESS_MSG = "成功！";
    private static final Integer ERROR_CODE = 0;
    private static final Integer SUCCESS_CODE = 1;

    private Integer code;
    private String msg;
    private T data;

    private ResultVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <E> ResultVO<E> success(E data) {
        return success(SUCCESS_MSG, data);
    }

    public static <E> ResultVO<E> success(String msg) {
        return success(msg, null);
    }

    public static <E> ResultVO<E> success(String msg, E data) {
        return success(SUCCESS_CODE, msg, data);
    }

    public static <E> ResultVO<E> success(Integer code, String msg, E data) {
        return new ResultVO<>(code, msg, data);
    }

    public static <E> ResultVO<E> failure(E data) {
        return success(ERROR_MSG, data);
    }

    public static <E> ResultVO<E> failure(String msg, E data) {
        return success(ERROR_CODE, msg, data);
    }
    public static <E> ResultVO<E> failure(Integer code, String msg) {
        return success(code, msg, null);
    }

    public static <E> ResultVO<E> failure(Integer code, String msg, E data) {
        return new ResultVO<>(code, msg, data);
    }
}
